package com.kolakcc.loljclient.view.ui;

import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import com.kolakcc.loljclient.StartupClass;
import com.kolakcc.loljclient.model.Champion;

public class ChampionBox extends JLabel {
	protected ImageIcon icon;
	public Champion champion;

	public ChampionBox(Champion c) throws Exception {
		super();
		this.champion = c;

		this.icon = new ImageIcon(c.getIcon());
		this.setIcon(this.icon);
		this.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					ChampionBox cb = (ChampionBox) e.getSource();
					StartupClass.openChampionDetails(cb.champion);
				}
			}

			public void mouseEntered(MouseEvent e) {
			}

			public void mouseExited(MouseEvent e) {
			}

			public void mousePressed(MouseEvent e) {
			}

			public void mouseReleased(MouseEvent e) {
			}
		});
	}
	public ChampionBox(Champion c, int w, int h) throws Exception {
		super();
		this.champion = c;

		this.icon = new ImageIcon(c.getIcon());
		this.setIcon(this.icon);
		this.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					ChampionBox cb = (ChampionBox) e.getSource();
					StartupClass.openChampionDetails(cb.champion);
				}
			}

			public void mouseEntered(MouseEvent e) {
			}

			public void mouseExited(MouseEvent e) {
			}

			public void mousePressed(MouseEvent e) {
			}

			public void mouseReleased(MouseEvent e) {
			}
		});
		this.setSize(w, h);
	}

	public void setSize(int w, int h) {
		if (w == 0 || h == 0) { w = 120; h = 120; }
		this.setIcon(new ImageIcon(this.icon.getImage().getScaledInstance(w, h,
				Image.SCALE_DEFAULT)));
		super.setSize(w, h);
		this.revalidate();
	}
}
